<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>var ctx="${ctx}";</script>
<div class="form-horizontal" role="form" >
	<input type="hidden" id="token" name="token" value="<%=request.getAttribute("token") %>" />
    <input id="id" value="${sale.id}"  type="hidden"/>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">主题:</label>
        <div class="col-md-9">
        	 <input id="topic" value="${sale.topic}"  data-check="require:true;code:^[a-zA-Z0-9\u4e00-\u9fa5]{1,30};message:不能为空" type="text" placeholder="主题" class="form-control" name="topic"/>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">图片:</label>
        <div class="col-md-9">
        	 <input class="fileInput" id="imageUploadify" type="file" name="file" multiple="multiple" accept="image/*"/>
        	 <div class="imageUploadify">   
				<c:if test="${not empty(sale.image)}">
				<img src="${sale.image}" style="width: 60px;height: 60px">
				</c:if>
			 </div>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">日期:</label>
        <div class="col-md-9">
        	  <input id="saleTime" type="text" class="input-md form-control layer-date" placeholder="开始时间"  name="saleTime" value="${fn:split(sale.startTime,' ')[0] }">
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">时间:</label>
        <div class="col-md-9">
        	  <select data-placeholder="选择时间段" id="sale-select-select" class="input-md form-control chosen-select layer-date" tabindex="4" name="saleTimeS">
                  <option value="00">00点</option>
                  <option value="01">01点</option>
                  <option value="02">02点</option>
                  <option value="03">03点</option>
                  <option value="04">04点</option>
                  <option value="05">05点</option>
                  <option value="06">06点</option>
                  <option value="07">07点</option>
                  <option value="08">08点</option>
                  <option value="09">09点</option>
                  <option value="10">10点</option>
                  <option value="11">11点</option>
                  <option value="12">12点</option>
                  <option value="13">13点</option>
                  <option value="14">14点</option>
                  <option value="15">15点</option>
                  <option value="16">16点</option>
                  <option value="17">17点</option>
                  <option value="18">18点</option>
                  <option value="19">19点</option>
                  <option value="20">20点</option>
                  <option value="21">21点</option>
                  <option value="22">22点</option>
                  <option value="23">23点</option>
              </select>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">分类:</label>
        <div class="col-md-9">
        	<select id="catId" placeholder="选择分类" class="chosen-select full-width" tabindex="4">
			</select>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">折扣:</label>
        <div class="col-md-9">
        	 <input value="${sale.discount}"  type="text" placeholder="折扣" class="form-control" name="discount"/>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">显示商品:</label>
        <div class="col-md-9">
        	 <input type="checkbox" class="js-switch" name="show_goods" <c:if test="${sale.showGoods==0 }">checked</c:if>/>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">启用:</label>
        <div class="col-md-9">
        	 <input type="checkbox" class="js-switch" name="enabled" <c:if test="${sale.enabled==0 }">checked</c:if>/>
        </div>
    </div>
</div>

<script>

$(function(){
	jQuery.checkall(false);
})

var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {
	var switchery = new Switchery(html);
}); 
$("#imageUploadify").uploadify({
	'buttonImage':'${ctx}/static/js/plugins/uploadify/uploadify-button.png',
    'swf': '${ctx}/static/js/plugins/uploadify/uploadify.swf',
    'uploader':'${ctx}/file/uploadOss',
    'onFallback' : function() {//检测FLASH失败调用 
    	alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");  
    },  
    'onUploadSuccess':function(file, data, response){
    	var jData = jQuery.parseJSON(data);
        $(".imageUploadify").html("<img src=\""+jData.data+"\" style=\"width: 60px;height: 60px;\">");
	}
});
$("#catId").chosen({ width: '100%' });
$.ajax({  
	url:'${ctx}/goodsCat/list',  		 					
	data:{						
	},   
	type: 'POST',
	dataType:'json',  
	success:function(response){
		if(response.code==0){
			var html=[];
			var data=response.data||[];
			for(var i=0;i<data.length;i++){
				html.push('<option value="'+data[i].id+'" ');
				html.push('>'+data[i].name+'</option>');
			}
			$("#catId").append(html.join(""));
			$("#catId").val("${sale.catId}");
			$("#catId").trigger("chosen:updated");
		}
	}  
 });
$(function(){
    var hh='${sale.startTime}';
	$("[name='saleTimeS']").val(hh.split(' ')[1].split(':')[0]);
	var saleTime = {
        elem: "#saleTime",
        format: "YYYY-MM-DD",
        istime: true,
        istoday: true,
        choose: function(datas) {
        }
    };
    laydate(saleTime);
})

</script>